package com.chapter.sample.juc.cas;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

public class AtomicReferenceDemo {
    public static void main(String[] args) {
        User z3 = new User("z3", 24);
        User l4 = new User("l4", 25);
        AtomicReference<User> userAtomicReference = new AtomicReference<>(z3);

        //userAtomicReference.set(user1);
        System.out.println(userAtomicReference.compareAndSet(z3, l4) + " : " + userAtomicReference.get());
        System.out.println(userAtomicReference.compareAndSet(z3, l4) + " : " + userAtomicReference.get());

    }
}

@Data
@AllArgsConstructor
@ToString
class User {
    String userName;

    int age;
}
